package ua.kpi_java_training.tyshchenko.module2.test;

import static junit.framework.Assert.*;
import org.junit.Before;
import org.junit.Test;
import ua.kpi_java_training.tyshchenko.module2.*;

/**
 * @author Vlad Tyshchenko
 * @version 1.0 19 June 2013
 */
public class MovementInSixDirectionsTest {
    int lengthStep;
    Position position;
    MovementInSixDirections movement;

    @Before
    public void setUp() {
        lengthStep = 1;
        position = new Position(new StabRandom(), new Habitat(new StabInputAllData()));
        movement = new MovementInSixDirections(position);
    }

    @Test
    public void testMoveLeftRight() {
        int coordinateY = position.getLength();
        int coordinateX = position.getWidth();
        movement.move(new StabRandom(2), lengthStep);
        assertEquals("move right Y", position.getLength(), coordinateY);
        assertEquals("move right X", position.getWidth(), coordinateX + 1);

        coordinateY = position.getLength();
        coordinateX = position.getWidth();
        movement.move(new StabRandom(5), lengthStep);
        assertEquals("move left Y", position.getLength(), coordinateY);
        assertEquals("move left X", position.getWidth(), coordinateX - 1);
    }

    @Test
    public void testMoveUpLeft() {
        int coordinateY = position.getLength();
        int coordinateX = position.getWidth();
        movement.move(new StabRandom(0), lengthStep);
        assertEquals("move up left Y", position.getLength(), coordinateY - 1);
        assertEquals("move up left X", position.getWidth(), coordinateX);

        coordinateY = position.getLength();
        coordinateX = position.getWidth();
        movement.move(new StabRandom(0), lengthStep);
        assertEquals("move up left Y", position.getLength(), coordinateY - 1);
        assertEquals("move up left X", position.getWidth(), coordinateX - 1);
    }

    @Test
    public void testMoveUpRight() {
        int coordinateY = position.getLength();
        int coordinateX = position.getWidth();
        movement.move(new StabRandom(1), lengthStep);
        assertEquals("move up right Y", position.getLength(), coordinateY - 1);
        assertEquals("move up right X", position.getWidth(), coordinateX + 1);

        coordinateY = position.getLength();
        coordinateX = position.getWidth();
        movement.move(new StabRandom(1), lengthStep);
        assertEquals("move up right Y", position.getLength(), coordinateY - 1);
        assertEquals("move up right X", position.getWidth(), coordinateX);
    }

    @Test
    public void testMoveDownRight() {
        int coordinateY = position.getLength();
        int coordinateX = position.getWidth();
        movement.move(new StabRandom(3), lengthStep);
        assertEquals("move down right Y", position.getLength(), coordinateY + 1);
        assertEquals("move down right X", position.getWidth(), coordinateX + 1);

        coordinateY = position.getLength();
        coordinateX = position.getWidth();
        movement.move(new StabRandom(3), lengthStep);
        assertEquals("move down right Y", position.getLength(), coordinateY + 1);
        assertEquals("move down right X", position.getWidth(), coordinateX);
    }

    @Test
    public void testMoveDownLeft() {
        int coordinateY = position.getLength();
        int coordinateX = position.getWidth();
        movement.move(new StabRandom(4), lengthStep);
        assertEquals("move down left Y", position.getLength(), coordinateY + 1);
        assertEquals("move down left X", position.getWidth(), coordinateX);

        coordinateY = position.getLength();
        coordinateX = position.getWidth();
        movement.move(new StabRandom(4), lengthStep);
        assertEquals("move down left Y", position.getLength(), coordinateY + 1);
        assertEquals("move down left X", position.getWidth(), coordinateX - 1);
    }
}
